package com.hgb.mall.admin.services.impl;

import com.github.pagehelper.PageHelper;
import com.hgb.mall.admin.services.SmsCouponHistoryService;
import com.hgb.mall.mbg.entity.SmsCouponHistory;
import com.hgb.mall.mbg.mapper.SmsCouponHistoryDynamicSqlSupport;
import com.hgb.mall.mbg.mapper.SmsCouponHistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static org.mybatis.dynamic.sql.SqlBuilder.isEqualToWhenPresent;

/**
 * 优惠券领取记录管理Service实现类
 * Created by hgb on 2020/11/6.
 */
@Service
public class SmsCouponHistoryServiceImpl implements SmsCouponHistoryService {
    @Autowired
    private SmsCouponHistoryMapper historyMapper;

    @Override
    public List<SmsCouponHistory> list(Long couponId, Integer useStatus, String orderSn, Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);

        return historyMapper.select(c -> c
                .where(SmsCouponHistoryDynamicSqlSupport.couponId, isEqualToWhenPresent(couponId))
                .and(SmsCouponHistoryDynamicSqlSupport.useStatus, isEqualToWhenPresent(useStatus))
                .and(SmsCouponHistoryDynamicSqlSupport.orderSn, isEqualToWhenPresent(orderSn)));

    }
}
